import {
  CART_DETAIL,
  INTEGRAL_CART_LIST
} from '@/api';
export default {
  data() {
    return {
      cartList: [],
      totalPrice: 0,
      integralCartList: [],
      integralTotalPrice: 0
    }
  },
  methods: {
    // 获取非积分购物车列表
    getCartList(tableId, storeId) {
      let that = this;
      let qsData = {
        table_id: tableId,
        store_id: storeId
      };
      that.$_get(CART_DETAIL, qsData).then(res => {
        if (res.code === 1) {
          // this.cartList = res.data.list;
          // this.totalPrice = res.data.total_price;
          if (res.data && res.data.list) {
            that.$store.commit('SET_CARTNUM', res.data.list.length)
            that.$storage.set('cartList', JSON.stringify(res.data.list))
            that.$storage.set('totalPrice', res.data.total_price)
          } else {
            that.$store.commit('SET_CARTNUM', 0)
            that.$storage.set('cartList', '')
            that.$storage.set('totalPrice', 0)
          }
        }
      });
    },
    // 获取积分购物车列表
    getIntegralCartList(tableId, storeId) {
      let that = this;
      let qsData = {
        table_id: tableId,
        store_id: storeId
      };
      that.$_get(INTEGRAL_CART_LIST, qsData).then(res => {
        if (res.code === 1) {
          // this.integralCartList = res.data;
          // this.integralTotalPrice = res.data.total_price;
          if (res.data && res.data.list) {
            that.$store.commit('SET_INTEGRALCARTNUM', res.data.list.length)
            that.$storage.set('integralCartList', JSON.stringify(res.data.list))
            that.$storage.set('integralTotalPrice', res.data.total_price)
          } else {
            that.$store.commit('SET_INTEGRALCARTNUM', 0)
            that.$storage.set('integralCartList', '')
            that.$storage.set('integralTotalPrice', 0)
          }
        } else {
          // that.$common.msgToShow(res.msg);
        }
      });
    },
  },
}